home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / mnt_201.zip / MNTUTIL.C < prev    next >
Text File  |  1992-01-05  |  4KB  |  85 lines

  1. /****************************************************************************/
  2. /* UTILITY module for RBBSMNT v2.01, a maintenance utility for RBBS-PC      */
  3. /*╒═════════════════════════════ NOTICE ═══════════════════════════════════╕*/
  4. /*│  A limited license is granted to all users of this program to make     │*/
  5. /*│  copies if this program and distribute those copies to other users     │*/
  6. /*│  on the following three conditions:                                    │*/
  7. /*│                                                                        │*/
  8. /*│    1.   This notice is NOT altered, bypassed or removed,               │*/
  9. /*│    2.   The program is not to be distributed to others in modified     │*/
  10. /*│         form. You may make changes for your own non-commercial use     │*/
  11. /*│    3.   No fee is to be charged (or any other consideration received)  │*/
  12. /*│         for copying or distributing these programs without an express  │*/
  13. /*│         written agreement with J. Terpstra, Bamestra RBBS, PO Box 66,  │*/
  14. /*│         Beemster, The Netherlands.                                     │*/
  15. /*│                                                                        │*/
  16. /*│Copyright (C) 1991, 1992 - Jan Terpstra, Bamestra RBBS, The Netherlands.│*/
  17. /*╘════════════════════════════════════════════════════════════════════════╛*/
  18. /****************************************************************************/
  19.  
  20. #include "rbbsmnt.h"                    /* definitions for this program     */
  21. #include "externs.h"                    /* external data references         */
  22.  
  23.   /**************************************************************************/
  24.   /* get RBBS message file header                                           */
  25.   /**************************************************************************/
  26.  
  27. void get_rbbs_hdr(int fp)
  28. {
  29.    int x;
  30.    long oldpos = lseek(fp, 0L, SEEK_CUR);/* store current file position     */
  31.  
  32.    lseek(fp, 0L, SEEK_SET);             /* seek back to header              */
  33.    read(fp, (char *)&hdr, (int)sizeof(RBBSHDR));/* read header              */
  34.    sscanf(hdr.last_msg, "%7u", &high_msg);
  35.    sscanf(hdr.user_count, "%5u", &num_users);
  36.    sscanf(hdr.first_msg_rec, "%7u", &first_rec);
  37.    sscanf(hdr.next_free_rec, "%7u", &next_rec);
  38.    sscanf(hdr.num_nodes, "%7u", &x);
  39.    if(first_rec != (x+2))
  40.    {
  41.       writelog("Inconsistent header info, repair with -FIX option",1,0);
  42.       exit(1);
  43.    }
  44.    last_rec = (int)(lseek(fp, 0L, SEEK_END)/128L);/* get real filesize      */
  45.    lseek(fp, oldpos, SEEK_SET);         /* restore file position            */
  46. }
  47.  
  48.  
  49.   /**************************************************************************/
  50.   /* put RBBS message file header                                           */
  51.   /**************************************************************************/
  52.  
  53. void put_rbbs_hdr(int fp)
  54. {
  55.    long oldpos = lseek(fp, 0L, SEEK_SET);/* store file position             */
  56.  
  57.    lseek(fp, 0L, SEEK_SET);             /* seek to header                   */
  58.    read(fp, (char *)&hdr, (int)sizeof(RBBSHDR));/* read header              */
  59.    itos(high_msg, hdr.last_msg, 8);
  60.    itos(num_users, hdr.user_count, 5);
  61.    itos(next_rec, hdr.next_free_rec, 7);
  62.    itos(last_rec, hdr.last_msg_rec, 7);
  63.    lseek(fp, 0L, SEEK_SET);             /* seek to header                   */
  64.    write(fp, (char *)&hdr, (int)sizeof(RBBSHDR));
  65.    lseek(fp, oldpos, SEEK_SET);         /* restore file position            */
  66. }
  67.  
  68.  
  69.   /**************************************************************************/
  70.   /* copy integer to non-terminated string, left adjusted                   */
  71.   /**************************************************************************/
  72.  
  73. void itos(int num,char *dest,int len)
  74. {
  75.    char temp[12];
  76.  
  77.    memset(dest, ' ', len);              /* set field to spaces              */
  78.    itoa(num, temp, 10);
  79.    memcpy(dest, temp, strlen(temp));
  80. }
  81.  
  82.  
  83. /*--------------------------------------------------------------------------*/
  84.  
  85.